
<form id="sanche-ding-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
    <div class="tab active">
        <div class="tab-labels">
            <div class="xian"></div>
            三者车定损
        </div>
        <div class="form-group" style="margin-bottom: 0">
            <div class="col-xs-12">
                <table class="table fieldlist" data-template="basictpl" data-name="res[basic]" id="first-table">
                    <tr class="tcxm-td">
                        <!--                                <td><input type="checkbox" name=""></td>-->
                        <td>{:__('车牌号')}</td>
                        <td>{:__('车辆品牌')}</td>
                        <td>{:__('车型型号')}</td>
                        <td>{:__('车辆年款')}</td>
                        <td>{:__('车架号')}</td>
                        <td>{:__('发动机号')}</td>
                        <td>{:__('维修厂名称')}</td>
                        <td>{:__('驾驶员')}</td>
                        <td>{:__('性别')}</td>
                        <td>{:__('联系电话')}</td>
                    </tr>
                    <tr class="form-inline">
                        <td><input type="text"  class="form-control" value="{$sanche.car_num}" name="row[car_num]" /></td>
                        <td><input type="text"  class="form-control" value="{$sanche.brand}" name="row[brand]" /></td>
                        <td><input type="text"  class="form-control" value="{$sanche.model}" name="row[model]"/></td>
                        <td><input type="text"  class="form-control" value="{$sanche.style}" name="row[style]" /></td>
                        <td><input type="text"  class="form-control" value="{$sanche.car_vin}" name="row[car_vin]" /></td>
                        <td><input type="text"  class="form-control" value="{$sanche.car_engine}" name="row[car_engine]" /></td>
                        <td><input type="text"  class="form-control" value="{$sanche.weixiuchang}" name="row[weixiuchang]" /></td>
                        <td><input type="text"  class="form-control" value="{$sanche.car_user}"  name="row[car_user]"/></td>
                        <td>
                            <input type="text"  class="form-control" list='canche_sex' value="{$sanche.sex}" name="row[sex]" />
                            <datalist id='canche_sex'>
                                <option value='男'>男</option>" +
                                <option value='女'>女</option>" +
                            </datalist>
                        </td>
                        <td><input type="text"  class="form-control" value="{$sanche.phone}" name="row[phone]" /></td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</form>
<!--配件-->
<form  id="sanche-pei-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
    <input type="hidden" name="row[sid]" value="{$sanche.id}">
    <div class="tab active">
        <div class="tab-labels">
            <div class="xian"></div>
            配件定损
        </div>
        <div class="form-group zhanshi">
            <label class="control-label col-xs-12 col-sm-2"></label>
            <div class="col-xs-12 ">
                <button  class="tab-label btn btn-primary btn-embossed" type="button" id=""  onclick="AddRow(document.getElementById('first-table1'),1)">增加</button>
                <button  class="tab-label btn btn-primary btn-embossed" type="button" style="background:#f75444" id="" onclick="sanche_pei_del(document.getElementById('first-table1'));">删除</button>
<!--                <button  class="tab-label btn btn-primary btn-embossed" type="button" id="" onclick="sanpei()">保存数据</button>-->
            </div>
        </div>
        <div class="form-group" style="margin-bottom: 0">
            <div class="col-xs-12">
                <table class="table fieldlist" data-template="basictpl" data-name="res[basic]" id="first-table1">
                    <tr class="tcxm-td">
                        <td style="width: 50px;">{:__('选择')}</td>
                        <td>{:__('序号')}</td>
                        <td>{:__('服务种类')}</td>
                        <td>{:__('配件名称')}</td>
                        <td>{:__('价格方案')}</td>
                        <td>{:__('价格')}</td>
                        <td>{:__('数量')}</td>
                        <td>{:__('金额')}</td>
                        <td>{:__('核定价格')}</td>
                        <td>{:__('核定数量')}</td>
                        <td>{:__('核定金额')}</td>
                        <td>{:__('备注')}</td>
                    </tr>

                    {empty name="sanpei"}
                    <tr class="form-inline">
                        <td><input type="checkbox" style='width: 20px!important;height: 20px;display: block;margin:0 auto;margin-top: 6px;' name="row[id][]" value="" id="pei_id" class="pei_id"></td>
                        <td><input type="text" id="pei_xuhao" class="form-control" value="1" name="row[xuhao][]" readonly/></td>
                        <td><input type="text" id="pei_type" class="form-control" value="" name="row[type][]" list="pei_sanche_type"/>
                            <datalist id='pei_sanche_type'>
                                {volist name="site.sanche_type" id="vo1"}
                                <option value='{$vo1}'>{$vo1}</option>
                                {/volist}
                            </datalist>
                        </td>
                        <td><input type="text" id="pei_name" class="form-control" value="" name="row[name][]"/></td>
                        <td><input type="text" id="pei_fangan" class="form-control" value="" name="row[fangan][]" list='pei_weixiuchang' />
                            <datalist id='pei_weixiuchang'>
                                {volist name="site.weixiuchang" id="vo2"}
                                <option value='{$vo2}'>{$vo2}</option>
                                {/volist}

                            </datalist>
                        </td>
                        <td><input type="text" id="pei_price" class="form-control pei_price" value="" name="row[price][]"  oninput="v()" /></td>
                        <td><input type="text" id="pei_num" class="form-control pei_num" value="" name="row[num][]"  oninput="v()"/></td>
                        <td><input type="text" id="pei_money" class="form-control pei_money" value="" name="row[money][]"  oninput="v()"/></td>
                        <td><input type="text" id="pei_price_he" class="form-control pei_price_he" value="0.00"  name="row[price_he][]"  oninput="v()" readonly/></td>
                        <td><input type="text" id="pei_num_he" class="form-control pei_num_he" value="" name="row[num_he][]" oninput="v()" readonly/></td>
                        <td><input type="text" id="pei_hejia" class="form-control pei_hejia" value="" name="row[hejia][]"  oninput="v()" readonly/></td>
                        <td><input type="text" id="pei_beizhu" class="form-control" value="" name="row[beizhu][]" /></td>
                    </tr>
                    {/empty}
                    {volist name="sanpei" id="vo"}
                    <tr class="form-inline">

                        <td><input type="checkbox" name="row[id][]"  style='width: 20px!important;height: 20px;display: block;margin:0 auto;margin-top: 6px;' id="pei_id" value="{$vo.id}" class="pei_id">
                            <input type="hidden" name="row[id][]"  value="{$vo.id}"></td>
                        <td><input type="text" id="pei_xuhao" class="form-control" value="{$vo.xuhao}" name="row[xuhao][]" readonly/></td>
                        <td><input type="text" id="pei_type" class="form-control" value="{$vo.type}" name="row[type][]" list="pei_sanche_type"/>
                            <datalist id='pei_sanche_type'>
                                {volist name="site.sanche_type" id="vo1"}
                                <option value='{$vo1}'>{$vo1}</option>
                                {/volist}
                            </datalist>
                        </td>
                        <td><input type="text" id="pei_name" class="form-control" value="{$vo.name}" name="row[name][]"/></td>
                        <td><input type="text" id="pei_fangan" class="form-control" value="{$vo.fangan}" name="row[fangan][]" list='pei_weixiuchang' />
                            <datalist id='pei_weixiuchang'>
                                {volist name="site.weixiuchang" id="vo2"}
                                <option value='{$vo2}'>{$vo2}</option>
                                {/volist}

                            </datalist>
                        </td>
                        <td><input type="text" id="pei_price" class="form-control pei_price" value="{$vo.price}" name="row[price][]"  oninput="v()"/></td>
                        <td><input type="text" id="pei_num" class="form-control pei_num" value="{$vo.num}" name="row[num][]"  oninput="v()"/></td>
                        <td><input type="text" id="pei_money" class="form-control pei_money" value="{$vo.money}" name="row[money][]" oninput="v()" /></td>
                        <td><input type="text" id="pei_price_he" class="form-control pei_price_he" value="{$vo.price_he}"  name="row[price_he][]" oninput="v()" readonly/></td>
                        <td><input type="text" id="pei_num_he" class="form-control pei_num_he" value="{$vo.num_he}" name="row[num_he][]" oninput="v()" readonly/></td>
                        <td><input type="text" id="pei_hejia" class="form-control pei_hejia" value="{$vo.hejia}" name="row[hejia][]"  oninput="v()" readonly/></td>
                        <td><input type="text" id="pei_beizhu" class="form-control" value="{$vo.beizhu}" name="row[beizhu][]" /></td>
                    </tr>
                    {/volist}
                </table>
                <table class="table fieldlist">
                    <tr class="form-inline form-inline1" style="border-top: 1px solid #e6e6e6;">
                        <td>小计</td>
                        <td><input type="text" class="form-control" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                            <td><input type="text" class="form-control" id="x_money" name="pei[x_money]" value="" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                        <td><input type="text" class="form-control" id="x_hejia" name="pei[x_hejia]" value="" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="hang">
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('合计')}:</label>
                <div class="col-xs-12 col-sm-10">
                    <input id="p_heji" class="form-control" name="pei[p_heji]" type="text" value="{$sanche.p_heji}" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('残值')}:</label>
                <div class="col-xs-12 col-sm-10">
                    <input id="canzhi" class="form-control"  name="pei[canzhi]" type="text" value="{$sanche.canzhi}" oninput="v()">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('配件总计')}:</label>
                <div class="col-xs-12 col-sm-10">
                    <input id="p_zongji" class="form-control" name="pei[p_zongji]"  type="text" value="{$sanche.p_zongji}" readonly>
                </div>
            </div>
        </div>
        <div class="hang">
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('核定合计')}:</label>
                <div class="col-xs-12 col-sm-10">
                    <input id="hd_p_heji" class="form-control" name="pei[hd_p_heji]" type="text" value="{$sanche.hd_p_heji}" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('核定残值')}:</label>
                <div class="col-xs-12 col-sm-10">
                    <input id="hd_canzhi" class="form-control"  name="pei[hd_canzhi]" type="text" value="{$sanche.hd_canzhi}" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('配件核定总计')}:</label>
                <div class="col-xs-12 col-sm-10">
                    <input id="hd_p_zongji" class="form-control" name="pei[hd_p_zongji]"  type="text" value="{$sanche.hd_p_zongji} " readonly>
                </div>
            </div>
        </div>
    </div>
</form>
<!--配件结束-->
<!--工时-->
<form  id="sanche-gong-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
    <input type="hidden" name="row[sid]" value="{$sanche.id}">
    <div class="tab active">
        <div class="tab-labels">
            <div class="xian"></div>
            工时核定
        </div>
        <div class="form-group zhanshi">
            <label class="control-label col-xs-12 col-sm-2"></label>
            <div class="col-xs-12 ">
                <button  class="tab-label btn btn-primary btn-embossed" type="button" onclick="AddRow(document.getElementById('first-table2'),1)">增加</button>
                <button  class="tab-label btn btn-primary btn-embossed" type="button" style="background:#f75444" onclick="sanche_gong_del(document.getElementById('first-table2'));">删除</button>
<!--                <button  class="tab-label btn btn-primary btn-embossed" type="button" onclick="sangong()">保存数据</button>-->
            </div>
        </div>
        <div class="form-group" style="margin-bottom: 0">
            <div class="col-xs-12">
                <table class="table fieldlist" data-template="basictpl" data-name="res[basic]" id="first-table2">
                    <tr class="tcxm-td">
                        <td style="width: 50px;">{:__('选择')}</td>
                        <td>{:__('序号')}</td>
                        <td>{:__('服务种类')}</td>
                        <td>{:__('名称')}</td>
                        <td>{:__('价格方案')}</td>
                        <td>{:__('价格')}</td>
                        <td>{:__('数量')}</td>
                        <td>{:__('金额')}</td>
                        <td>{:__('核定价格')}</td>
                        <td>{:__('核定数量')}</td>
                        <td>{:__('核定金额')}</td>
                        <td>{:__('备注')}</td>
                    </tr>

                    {empty name="sangong"}
                    <tr class="form-inline">
                        <td><input type="checkbox" style='width: 20px!important;height: 20px;display: block;margin:0 auto;margin-top: 6px;' name="row[id][]" value="" id="gong_id"  class="gong_id"></td>
                        <td><input type="text" id="gong_xuhao" class="form-control" value="1" name="row[xuhao][]" readonly/></td>
                        <td><input type="text" id="gong_type" class="form-control" value="" name="row[type][]" list="gong_sanche_type"/>
                            <datalist id='gong_sanche_type'>
                                {volist name="site.sanche_type" id="vo1"}
                                <option value='{$vo1}'>{$vo1}</option>
                                {/volist}
                            </datalist>
                        </td>
                        <td><input type="text" id="gong_name" class="form-control" value="" name="row[name][]"/></td>
                        <td><input type="text" id="gong_fangan" class="form-control" value="" name="row[fangan][]" list='gong_weixiuchang' />
                            <datalist id='gong_weixiuchang'>
                                {volist name="site.weixiuchang" id="vo2"}
                                <option value='{$vo2}'>{$vo2}</option>
                                {/volist}

                            </datalist>
                        </td>
                        <td><input type="text" id="gong_price" class="form-control gong_price" value="" name="row[price][]"  oninput="v1()" /></td>
                        <td><input type="text" id="gong_num" class="form-control gong_num" value="" name="row[num][]"  oninput="v1()"/></td>
                        <td><input type="text" id="gong_money" class="form-control gong_money" value="" name="row[money][]"  oninput="v1()"/></td>
                        <td><input type="text" id="gong_price_he" class="form-control gong_price_he" value="0.00"  name="row[price_he][]"  oninput="v1()" readonly/></td>
                        <td><input type="text" id="gong_num_he" class="form-control gong_num_he" value="" name="row[num_he][]" oninput="v1()" readonly/></td>
                        <td><input type="text" id="gong_hejia" class="form-control gong_hejia" value="" name="row[hejia][]"  oninput="v1()" readonly/></td>
                        <td><input type="text" id="gong_beizhu" class="form-control" value="" name="row[beizhu][]" /></td>
                    </tr>
                    {/empty}
                    {volist name="sangong" id="vo"}
                    <tr class="form-inline">

                        <td><input type="checkbox" name="row[id][]"  style='width: 20px!important;height: 20px;display: block;margin:0 auto;margin-top: 6px;' id="gong_id" value="{$vo.id}"  class="gong_id">
                            <input type="hidden" name="row[id][]"  value="{$vo.id}"></td>
                        <td><input type="text" id="gong_xuhao" class="form-control" value="{$vo.xuhao}" name="row[xuhao][]" readonly/></td>
                        <td><input type="text" id="gong_type" class="form-control" value="{$vo.type}" name="row[type][]" list="gong_sanche_type"/>
                            <datalist id='gong_sanche_type'>
                                {volist name="site.sanche_type" id="vo1"}
                                <option value='{$vo1}'>{$vo1}</option>
                                {/volist}
                            </datalist>
                        </td>
                        <td><input type="text" id="gong_name" class="form-control" value="{$vo.name}" name="row[name][]"/></td>
                        <td><input type="text" id="gong_fangan" class="form-control" value="{$vo.fangan}" name="row[fangan][]" list='gong_weixiuchang' />
                            <datalist id='gong_weixiuchang'>
                                {volist name="site.weixiuchang" id="vo2"}
                                <option value='{$vo2}'>{$vo2}</option>
                                {/volist}

                            </datalist>
                        </td>
                        <td><input type="text" id="gong_price" class="form-control gong_price" value="{$vo.price}" name="row[price][]"  oninput="v1()"/></td>
                        <td><input type="text" id="gong_num" class="form-control gong_num" value="{$vo.num}" name="row[num][]"  oninput="v1()"/></td>
                        <td><input type="text" id="gong_money" class="form-control gong_money" value="{$vo.money}" name="row[money][]" oninput="v1()" /></td>
                        <td><input type="text" id="gong_price_he" class="form-control gong_price_he" value="{$vo.price_he}"  name="row[price_he][]" oninput="v1()" readonly/></td>
                        <td><input type="text" id="gong_num_he" class="form-control gong_num_he" value="{$vo.num_he}" name="row[num_he][]" oninput="v1()" readonly/></td>
                        <td><input type="text" id="gong_hejia" class="form-control gong_hejia" value="{$vo.hejia}" name="row[hejia][]"  oninput="v1()" readonly/></td>
                        <td><input type="text" id="gong_beizhu" class="form-control" value="{$vo.beizhu}" name="row[beizhu][]" /></td>
                    </tr>
                    {/volist}
                </table>
                <table class="table fieldlist">
                    <tr class="form-inline form-inline1" style="border-top: 1px solid #e6e6e6;">
                        <td>小计</td>
                        <td><input type="text" class="form-control" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                        <td><input type="text" class="form-control" id="g_money" name="gong[g_money]" value="" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                        <td><input type="text" class="form-control" id="g_hejia" name="gong[g_hejia]" value="" readonly></td>
                        <td><input type="text" class="form-control" readonly></td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="hang">
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('施救费')}:</label>
                <div class="col-xs-12 col-sm-10">
                    <input id="g_shijiu" class="form-control" name="gong[g_shijiu]" type="text" value="{$sanche.g_shijiu}"  oninput="v1()">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('工时总计')}:</label>
                <div class="col-xs-12 col-sm-10">
                    <input id="g_zongji" class="form-control"  name="gong[g_zongji]" type="text" value="{$sanche.g_zongji}">
                </div>
            </div>
        </div>
        <div class="hang">
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('核定施救费')}:</label>
                <div class="col-xs-12 col-sm-10">
                    <input id="hd_g_shijiu" class="form-control" name="gong[hd_g_shijiu]" type="text" value="{$sanche.hd_g_shijiu}"  oninput="v1()" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('工时核定总计')}:</label>
                <div class="col-xs-12 col-sm-10">
                    <input id="hd_g_zongji" class="form-control"  name="gong[hd_g_zongji]" type="text" value="{$sanche.hd_g_zongji}" readonly>
                </div>
            </div>
        </div>
        <div class="hang">
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('费用合计')}:</label>
                <div class="col-xs-12 col-sm-10">
                    <input id="heji" class="form-control" name="gong[heji]" type="text" value="{$sanche.heji}" >
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('核定合计')}:</label>
                <div class="col-xs-12 col-sm-10">
                    <input id="hd_g_heji" class="form-control" type="text" value="{$sanche.hd_g_heji}" readonly>
                </div>
            </div>
        </div>
        <div class="hang">
            <div class="form-group" style="width: 100%;">
                <label class="control-label col-xs-12 col-sm-2">{:__('备注说明')}:</label>
                <div class="col-xs-12 col-sm-10">
                    <textarea id="beizhu" class="form-control" name="gong[beizhu]" type="text" cols="10" rows="5" >{$sanche.beizhu}</textarea>
                </div>
            </div>
        </div>
    </div>
</form>
<!--工时结束-->
<!--理算-->
{include file="buchang/chakan/lisuan" /}
<!--理算结束-->

<div class="form-group zhanshi" style="margin-top: 50px;padding-bottom: 50px;">
    <label class="control-label col-xs-12 col-sm-2"></label>
    <div class="col-xs-12 " style="margin: auto;">
        <button type="button" class="btn btn-primary btn-embossed " style="margin-left: 10px;" onclick="zuihou_save()">{:__('保存并关闭')}</button>
    </div>
</div>



<script src="/assets/js/ace1.4/assets/js/jquery.min.js" type="text/javascript"></script>
<script src="/assets/js/ace1.4/assets/js/add.js" type="text/javascript"></script>
<!--公共-->
<script>
    //判断
    $(document).ready(function() {
        if({$sanche.status} != 0 || {$type} == 1){
            $('input').attr('readonly','readonly')
            $('textarea').attr('readonly','readonly')
            $('input[type=checkbox]').attr('disabled','disabled')
            $('input[type=radio]').attr('disabled','disabled')
            $('select').attr('disabled','disabled');
        }

        if({$sanche.status} == 0 && {$type} == 0){
            $('.zhanshi').show()
        }
    })
    //最后保存
    function zuihou_save(){
        layer.confirm('确认保存吗？', {
            btn: ['确定', '取消'], //按钮
            shade: false //不显示遮罩
        }, function(index,layero) {
            $(layero).find('.layui-layer-btn0').css('pointer-events','none');// 将确认按钮鼠标事件设置为无效
            $(layero).find('.layui-layer-btn0').html('保存中...');// 将确认按钮鼠标事件设置为无效
            console.log('11111')
            sangong();
            sanpei();
            buchangkuan();
            qita_save();
            var formDataObj = {};
            $.each($('#sanche-ding-form').serializeArray(), function(index, field){
                if((field.name).substring(0,3) =='row'){
                    formDataObj[field.name] = field.value;
                }
            });

            $.each($('#sanche-pei-form').serializeArray(), function(index, field){
                if((field.name).substring(0,3) !='row'){
                    formDataObj[field.name] = field.value;
                }
            });

            $.each($('#sanche-gong-form').serializeArray(), function(index, field){
                if((field.name).substring(0,3) !='row'){
                    formDataObj[field.name] = field.value;
                }
            });
            formDataObj['row[kuai_shen]'] = $('input[name="kuai_shen"]:checked').val();

            formDataObj['sid'] = {$sanche.id};
            formDataObj['bid'] = {$sanche.bid};
            $.ajax({
                url: "{:url('buchang/chakan/zuihou_save')}",
                data: formDataObj,
                type: 'post',
                dataType: 'json',
                success: function (ret) {
                    if(ret.code == 1){
                        var res = ret.data
                        for (var i = 0; i < res.length; i++) {
                            $("#sanche_id_"+res[i].id,window.parent.document).val(res[i].id);
                            $("#sanche_xuhao_"+res[i].id,window.parent.document).val(res[i].xuhao);
                            $("#sanche_car_num_"+res[i].id,window.parent.document).val(res[i].car_num);
                            $("#sanche_car_user_"+res[i].id,window.parent.document).val(res[i].car_user);
                            $("#sanche_sex_"+res[i].id,window.parent.document).val(res[i].sex);
                            $("#sanche_phone_"+res[i].id,window.parent.document).val(res[i].phone);
                            $("#sanche_brand_"+res[i].id,window.parent.document).val(res[i].brand);
                            $("#sanche_model_"+res[i].id,window.parent.document).val(res[i].model);
                            $("#sanche_style_"+res[i].id,window.parent.document).val(res[i].style);
                            $("#sanche_car_vin_"+res[i].id,window.parent.document).val(res[i].car_vin);
                            $("#sanche_car_engine_"+res[i].id,window.parent.document).val(res[i].car_engine);
                            $("#sanche_weixiuchang_"+res[i].id,window.parent.document).val(res[i].weixiuchang);
                            $("#sanche_heji_"+res[i].id,window.parent.document).val(res[i].heji);
                            $("#sanche_c_zongji_"+res[i].id,window.parent.document).val(res[i].c_zongji);
                            $("#sanche_sanche_huizong_"+res[i].id,window.parent.document).val(res[i].sanche_huizong);
                            $("#sanche_status_"+res[i].id,window.parent.document).val(res[i].status);
                        }
                        layer.msg('保存成功！', {
                            time: 1000,
                            icon: 1
                        }, function(index) {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //执行关闭
                        })
                    }else{
                        layer.alert(res.msg)
                    }
                }
            })
        })
    }

    function msg(res){
        if(res.code == 1){
            layer.msg(res.msg, {
                time: 1000,
                icon: 1
            })
        }else{
            layer.msg(res.msg, {
                time: 1000,
                icon: 2
            })
        }
    }
</script>
<!--配件-->
<script>
    v();
    //配件计算
    function v(){
        var price = document.getElementsByClassName('pei_price');
        var num = document.getElementsByClassName('pei_num');
        var moneys = document.getElementsByClassName('pei_money');
        var price_he = document.getElementsByClassName('pei_price_he');
        var num_he = document.getElementsByClassName('pei_num_he');
        var hejias = document.getElementsByClassName('pei_hejia');
        var money1 = new Array();
        for (var i = 0; i < price.length; i++) {
            money1[i] = price[i].value * num[i].value;
            moneys[i].value = money1[i];

            hejias[i].value = (price_he[i].value * num_he[i].value).toFixed(2);;
        }
        var money = new Array();
        var result = 0;
        for(var i = 0;i < moneys.length;i++){
            money[i] = parseFloat(moneys[i].value);
            result += money[i];
        }
        var benche_money = document.getElementById('x_money');
        var benche_hejia = document.getElementById('x_hejia');
        var benche_heji = document.getElementById('p_heji');
        if (result>0) {
            benche_money.value = result.toFixed(2);
            benche_heji.value = result.toFixed(2);
        }

        var hejia = new Array();
        var results = 0;
        for(var i = 0;i < hejias.length;i++){
            hejia[i] = parseFloat(hejias[i].value);
            results += hejia[i];
        }
        if (results>0) {
            benche_hejia.value = results.toFixed(2);
        }
        var p_heji = document.getElementById('p_heji').value;
        var canzhi = document.getElementById('canzhi').value;
        var p_zongji = document.getElementById('p_zongji');
        var number = (Number(p_heji)-Number(canzhi)).toFixed(2);
        p_zongji.value = number;
        var p_zongji1 = document.getElementById('p_zongji').value;
        var g_zongji1 = document.getElementById('g_zongji').value;
        var numbers = (Number(p_zongji1)+Number(g_zongji1)).toFixed(2);
        $("#heji").val(numbers)
        $("#sanche_money").val(numbers)
        v2()
    }
    //删除配件
    function sanche_pei_del(table){
        var row_length = table.rows.length - 1;
        if( row_length == 1){
            layer.msg('至少保留一条',{time:1000,icon:2})
            return false
        }
        DeleteRow(table,1);
        v()
        return false
        var id = '';
        $('.pei_id').each(function(){
            if($(this).is(':checked')){
                id += ','+$(this).val();
            }
        })
        id=id.substring(1);
        if(!id){
            layer.msg('请选择要删除的数据',{time:1000,icon:2})
            return false
        }

        var row_length = table.rows.length - 1;
        var ids = id.split(",");
        if( ids.length == row_length || row_length == 1){
            layer.alert('至少保留一条')
            return false
        }
        layer.confirm('确认删除吗？', {
            btn: ['确定', '取消'], //按钮
            shade: false //不显示遮罩
        }, function(index) {
            $.ajax({
                url:"{:url('buchang/chakan/canche_pei_delete')}",
                data:{id:id},
                type:'post',
                dataType:'json',
                success:function(res){
                    DeleteRow(table,1);
                    v()
                }
            })
        })

    }
    //保存配件
    function sanpei(){
        // var formDataObj = {};
        // $.each($('#sanche-pei-form').serializeArray(), function(index, field){
        //     if((field.name).substring(0,3) =='row'){
        //         formDataObj[field.name] = field.value;
        //     }
        // });
        // layer.confirm('确认保存吗？', {
        //     btn: ['确定', '取消'], //按钮
        //     shade: false //不显示遮罩
        // }, function(index,layero) {
        //     $(layero).find('.layui-layer-btn0').css('pointer-events','none');// 将确认按钮鼠标事件设置为无效
        //     $(layero).find('.layui-layer-btn0').html('保存中...');// 将确认按钮鼠标事件设置为无效
            $.ajax({
                url: "{:url('buchang/chakan/peijian')}",
                data: $('#sanche-pei-form').serializeArray(),
                type: 'post',
                dataType: 'json',
                success: function (res) {
                    // msg(res)
                }
            })
        // })


    }

</script>
<!--工时-->
<script>
    v1()
    //公式点击计算
    function v1(){
        var price = document.getElementsByClassName('gong_price');
        var num = document.getElementsByClassName('gong_num');
        var moneys = document.getElementsByClassName('gong_money');
        var price_hes = document.getElementsByClassName('gong_price_he');
        var num_hes = document.getElementsByClassName('gong_num_he');
        var hejias = document.getElementsByClassName('gong_hejia');
        var money1 = new Array();
        for (var i = 0; i < price.length; i++) {
            money1[i] = price[i].value * num[i].value;
            moneys[i].value = money1[i];
            hejias[i].value = (price_hes[i].value * num_hes[i].value).toFixed(2);
        }
        var money = new Array();
        var result = 0;
        for(var i = 0;i < moneys.length;i++){
            money[i] = parseFloat(moneys[i].value);
            result += money[i];
        }
        var benche_money = document.getElementById('g_money');
        if (!isNaN(result)) {
            benche_money.value = result.toFixed(2);
        }
        var hejia = new Array();
        var results = 0;
        for(var i = 0;i < hejias.length;i++){
            hejia[i] = parseFloat(hejias[i].value);
            results += hejia[i];
        }
        var benche_hejia = document.getElementById('g_hejia');
        if (results>0) {
            benche_hejia.value = results.toFixed(2);
        }
        var g_hejia = document.getElementById('g_hejia').value;
        var g_shijiu = document.getElementById('g_shijiu').value;
        var g_zongji = document.getElementById('g_zongji');
        var number = (Number(benche_money.value)+Number(g_shijiu)).toFixed(2);
        g_zongji.value = number;
        var p_zongji = document.getElementById('p_zongji').value;
        var heji = document.getElementById('heji');
        var numbers = (Number(g_zongji.value)+Number(p_zongji)).toFixed(2);
        heji.value = numbers;
        $("#sanche_money").val(numbers)
        v2()
    }
    //工时保存
    function sangong(){
        // var formDataObj = {};
        // $.each($('#sanche-gong-form').serializeArray(), function(index, field){
        //     if((field.name).substring(0,3) =='row'){
        //         formDataObj[field.name][] = field.value;
        //     }
        // });
        // layer.confirm('确认保存吗？', {
        //     btn: ['确定', '取消'], //按钮
        //     shade: false //不显示遮罩
        // }, function(index,layero) {
        //     $(layero).find('.layui-layer-btn0').css('pointer-events','none');// 将确认按钮鼠标事件设置为无效
        //     $(layero).find('.layui-layer-btn0').html('保存中...');// 将确认按钮鼠标事件设置为无效
            $.ajax({
                url: "{:url('buchang/chakan/save_gong')}",
                data: $('#sanche-gong-form').serializeArray(),
                type: 'post',
                dataType: 'json',
                success: function (res) {
                    // msg(res)
                }
            })
        // })


    }
    //工时删除
    function sanche_gong_del(table){
        var row_length = table.rows.length - 1;
        if( row_length == 1){
            layer.msg('至少保留一条',{time:1000,icon:2})
            return false
        }
        DeleteRow(table,1);
        v1()
        return false
        var id = '';
        $('.gong_id').each(function(){
            if($(this).is(':checked')){
                id += ','+$(this).val();
            }
        })
        id=id.substring(1);
        if(!id){
            layer.msg('请选择要删除的数据',{time:1000,icon:2})
            return false
        }

        var row_length = table.rows.length - 1;
        var ids = id.split(",");
        if( ids.length == row_length || row_length == 1){
            layer.alert('至少保留一条')
            return false
        }
        layer.confirm('确认删除吗？', {
            btn: ['确定', '取消'], //按钮
            shade: false //不显示遮罩
        }, function(index) {
            $.ajax({
                url:"{:url('buchang/chakan/sanche_pei_del')}",
                data:{id:id},
                type:'post',
                dataType:'json',
                success:function(res){
                    DeleteRow(table,1);
                    v1()
                }
            })
        })

    }
</script>